package com.boc.ewr.risk.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.boc.ewr.bcimp.entity.Cac;
import com.boc.ewr.bcimp.entity.Pro;
import com.boc.ewr.risk.service.IProRiskService;
import com.boc.ewr.util.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author : Wzz
 * @create : 2023-06- 02- 9:48
 * @desc : 风险预警-涉及Pro的风险预警清单
 */
@Api(tags = "风险预警-涉及Pro的风险预警清单")
@RestController
@RequestMapping("/risk/proRisk")
@Slf4j
public class ProRiskController extends JeecgController<Pro, IProRiskService> {

    @Value("${jeecg.path.upload}")
    private String upLoadPath;

    /**
     * 新增、变更协议清单  分页列表查询
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    //@AutoLog(value = "风险预警-新增、变更协议清单")
    @ApiOperation(value = "风险预警-新增、变更协议清单", notes = "风险预警-新增、变更协议清单")
    @GetMapping(value = "/genChangeRisk")
    public Result<IPage<Pro>> genChangeRisk(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {

        List<Pro> proList = service.changeRisk();

        return Result.OK(PageUtil.create(proList,pageNo,pageSize));
    }

    /**
     * 新增、变更协议清单 导出excel
     */
    //@RequiresPermissions("com.boc.ewr:cac:exportXls")
    @RequestMapping(value = "/exportXls/changeRisk")
    public ModelAndView exportChangeRiskXls() {
        String title = "新增、变更协议清单";

        List<Pro> proList = service.changeRisk();

        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.FILE_NAME, title);
        mv.addObject(NormalExcelConstants.CLASS, Pro.class);
        //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
        ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + this.getLoginUser().getRealname(), title);
        exportParams.setImageBasePath(upLoadPath);
        //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
        mv.addObject(NormalExcelConstants.PARAMS, exportParams);
        mv.addObject(NormalExcelConstants.DATA_LIST, proList);
        return mv;
    }


    /**
     * 同一客户号下不同对账渠道  分页列表查询
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    //@AutoLog(value = "风险预警-同一客户号下不同对账渠道")
    @ApiOperation(value = "风险预警-同一客户号下不同对账渠道", notes = "风险预警-同一客户号下不同对账渠道")
    @GetMapping(value = "/genSameCusmNoDifChannelRisk")
    public Result<IPage<Pro>> genSameCusmNoDifChannelRisk(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {

        List<Pro> proList = service.sameCusmNoDifChannelRisk();

        return Result.OK(PageUtil.create(proList,pageNo,pageSize));
    }

    private LoginUser getLoginUser() {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        return sysUser;
    }

    /**
     * 同一客户号下不同对账渠道 导出excel
     */
    //@RequiresPermissions("com.boc.ewr:cac:exportXls")
    @RequestMapping(value = "/exportXls/sameCusmNoDifChannelRisk")
    public ModelAndView exportSameCusmNoDifChannelRisk() {
        String title = "同一客户号下不同对账渠道";

        List<Pro> proList = service.sameCusmNoDifChannelRisk();

        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.FILE_NAME, title);
        mv.addObject(NormalExcelConstants.CLASS, Pro.class);
        //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
        ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + this.getLoginUser().getRealname(), title);
        exportParams.setImageBasePath(upLoadPath);
        //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
        mv.addObject(NormalExcelConstants.PARAMS, exportParams);
        mv.addObject(NormalExcelConstants.DATA_LIST, proList);
        return mv;
    }
}
